// Helper EventDispatcher

(function(window, undefined) {

Helper.EventDispatcher = Helper(function( target ) {
	var _target = target;
	var _bindedEvents = {};

	return {
		addEventListener: function( event, handler ) {
			console.log( this, "addEventListener" );
			
			_bindedEvents[event] = handler;
		},
		
		removeEventListener: function( event ) {
			console.log( this, "removeEventListener" );
		
			_bindedEvents[event] = undefined;
			delete _bindedEvents[event];
		},
		
		dispatchEvent: function( event ) {
			//console.log( this, "dispatchEvent", _target, event );
			
			var handler = _bindedEvents[event];
			
			if ( handler == undefined || typeof handler != "function" ) {
				return;
			};
			
			var args = Array.prototype.slice.call( arguments, 0 );
			args.shift();
			
			handler.apply( _target, args );
		}
	};
});

})( window );